import { defineStore } from 'pinia';
import { type OrderDTO } from '@/interface/order';

export const useOrderStore = defineStore('order', {
    persist: {
        key: 'orderStore',
        storage: window.sessionStorage
    },
    state: (): { order: OrderDTO, noticeReservation: string, statement: string, isCheck: number } => ({
        order: {
            isExplain: 0,
            leaderName: null,
            leaderPhone: null,
            peopleNum: 0,
            platform: '小程序',
            ptId: 2,
            teamName: null,
            tickerId: null,
            visitDate: null,
            visitPeriod: null
        },
        noticeReservation: '',
        statement: '',
        isCheck: 0
    }),
    actions: {
        setOrder(order: OrderDTO) {
            let key: keyof OrderDTO;
            for (key in order) {
                this.order[key] = order[key];
            }
        },
        resetOrder() {
            this.order.isExplain = 0;
            this.order.leaderName = null;
            this.order.leaderPhone = null;
            this.order.peopleNum = null;
            this.order.platform = '小程序';
            this.order.ptId = 2;
            this.order.teamName = null;
            this.order.tickerId = null;
            this.order.visitDate = null;
            this.order.visitPeriod = null;
        }
    },
    getters: {
        orderGetter(state: any) {
            return state.order;
        }
    }
});
